/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Jakin;

import com.thoughtworks.xstream.XStream;
import java.util.Iterator;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import logica.LogicaAlumno;
import logica.util.Perfil;
import logica.util.ProfilesUtil;
import modelo.DTO.DTOFactory;
import modelo.DTO.PerfilAlumno;
import modelo.DTO.PerfilesAlumnos;

/**
 *
 * @author Ion B. Padilla
 */
@WebService()
public class JakinService {

    private final String TEMPDIR = "Dcom.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace=false ";


    /**
     * Web service operation
     */
    @WebMethod(operationName = "getStudentsProfiles")
    public String getStudentsProfiles() {
        System.getProperty(TEMPDIR);
        DTOFactory factoria=new DTOFactory();
        XStream xStream=new XStream();
        xStream.alias("perfiles", PerfilesAlumnos.class);
        ProfilesUtil pUtil=ProfilesUtil.getInstance();
        pUtil.reMake();
        pUtil.addStandarProfiles();
        pUtil.setCurso(6);
        LogicaAlumno lAlumno=new LogicaAlumno();
        //añadimos los perfiles estandar de la aplicacion
        return xStream.toXML(factoria.fromDTOPerilAlumno2PerfilesAlumnos(lAlumno.getPerfilesAlumnos(ProfilesUtil.getInstance())));
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "getStudentProfile")
    public String getStudentProfile(@WebParam(name = "nombre")
    String nombre) {
        System.getProperty(TEMPDIR);
       // ErrorAlumno errorAlumno = new ErrorAlumno();
      //  errorAlumno.setName("Alumno no encontrado");
        DTOFactory factoria=new DTOFactory();
        XStream xStream=new XStream();
        xStream.alias("perfiles", PerfilAlumno.class);
        ProfilesUtil pUtil=ProfilesUtil.getInstance();
        pUtil.reMake();
        pUtil.addStandarProfiles();
        pUtil.setCurso(6);
        LogicaAlumno lAlumno=new LogicaAlumno();
        //añadimos los perfiles estandar de la aplicacion

      //  return xStream.toXML(errorAlumno);

       // if (lAlumno.noEstaAlumno(nombre)==1){
          //  return xStream.toXML(errorAlumno);
       // }
       // else
            return xStream.toXML(factoria.fromDTOPerilAlumno2PerfileAlumno(lAlumno.noEstaAlumno(nombre), lAlumno.getPerfilAlumno(nombre, ProfilesUtil.getInstance())));
    }

    public class ErrorAlumno {

        private String name;

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

    }


}
